package cn.dlc.com.service.impl;

import cn.dlc.com.mapper.SysUserMapper;
import cn.dlc.com.pojo.SysRole;
import cn.dlc.com.pojo.SysUser;
import cn.dlc.com.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author deng
 * @date 2021/6/24 17:27
 **/
@Service
@Transactional
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser user = userMapper.findByName(s);

        List<SysRole> authorities = (List<SysRole>) user.getAuthorities();

        for (SysRole authority : authorities) {
            System.out.println("sdfsdf: -> " + authority.getRoleName());
        }

        return user;
    }
}
